<?php
if(!isset($_SESSION)){
	session_start();
}
if(empty($_SESSION['logind'])){
	echo '<script>top.location.href="./login.php";</script>';
	exit();
}
include '../luodi.php';
$luodi = json_decode($luodi, true);
if($_SERVER['REQUEST_METHOD'] == 'POST'){
	if(isset($_POST['add'])){
		array_push($luodi, $_POST['domain']);
		$luodi = json_encode($luodi);
		file_put_contents('../luodi.php', '<?php'.chr(10). '$luodi = \'' . $luodi.'\';'.chr(10).'?>');
		header('Content-Type:text/html;charset=utf-8');
		echo '<script>alert("添加成功！");location.href=location.href;</script>';
		exit();
	}else if(isset($_POST['save'])){
		if(!isset($_POST['urls'])){
			$_POST['urls'] = array();
		}
		$luodi = json_encode($_POST['urls']);
		file_put_contents('../luodi.php', '<?php'.chr(10).'$luodi = \'' . $luodi.'\';'.chr(10).'?>');
		header('Content-Type:text/html;charset=utf-8');
		echo '<script>alert("保存成功！");location.href=location.href;</script>';
		exit();
	}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>后台管理系统</title>
<link href="css/style.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="js/jquery.js"></script>

<script language="javascript">
$(function(){	
	//导航切换
	$(".imglist li").click(function(){
		$(".imglist li.selected").removeClass("selected")
		$(this).addClass("selected");
	});
	
	$('.remove').click(function(){
		$(this).parent().parent('tr').remove();
	});
});

function checkadd(){
	if(document.newsform.domain.value==""){
		alert("请输入要添加的域名地址！");
		document.newsform.domain.focus();
		return false;
	}
}
</script>
</head>
<body>
<div class="rightinfo">
	<form action="" method="post" name="newsform" onSubmit="return checkadd();">
	<label>域名</label>&nbsp;&nbsp;<input name="domain" type="text" class="dfinput" value="" />
	<input type="submit" class="btn add" name="add" value="添 加"/>
	</form>
	<form action="" method="post" name="listform">
    <table class="imgtable" style="margin-top:8px;">
    <thead>
    <tr>
    <th style="width:90px;">ID</th>
    <th>域名</th>
    <th>操作</th>
    </tr>
    </thead>
    <tbody>
<?php if($luodi):foreach($luodi as $key => $url):?>
	<tr height="35px">
		<td style="width:90px;"><?php echo $key+1;?></td>
		<td><input name="urls[]" type="text" class="dfinput" value="<?php echo $url;?>" /></td>
		<td><a class="remove" href="javascript:;">移除</a>（移除后请点击保存）</td>
	</tr>
<?php endforeach;endif;?>
	
    </tbody>
    </table>
	<input type="submit" class="btn save" name="save" style="margin-top:20px;" value="保 存"/>&nbsp;&nbsp;&nbsp;&nbsp;<font style="color:red;">为不影响使用，请不要全部移除</font>
	</form>
</div>
<script type="text/javascript">
	$('.imgtable tbody tr:odd').addClass('odd');
</script>
</body>
</html>